Bases: ModelOperationalMetric
LM counter metric base; subclass to add one, don't compile it directly.
Subclasses set _phase to one of "inference", "reward", or
"optimizer" to read from the corresponding counter set on each
bound LM. Counters are populated by the LM based on the active
op_scope (contextvar) the trainer sets for each phase.
The metric binds itself automatically to every LanguageModel
reachable from the program (and their .fallback chains) when
program.compile() is called, and counters are summed across all.
Example (with a concrete subclass):
program.compile(
metrics=[
synalinks.metrics.InputTokens(),
],
)
Source code in synalinks/src/metrics/lm_metrics.py
| @synalinks_export(
[
"synalinks.metrics.LMOperationalMetric",
"synalinks.LMOperationalMetric",
]
)
class LMOperationalMetric(ModelOperationalMetric):
"""LM counter metric base; subclass to add one, don't compile it directly.
Subclasses set `_phase` to one of ``"inference"``, ``"reward"``, or
``"optimizer"`` to read from the corresponding counter set on each
bound LM. Counters are populated by the LM based on the active
``op_scope`` (contextvar) the trainer sets for each phase.
The metric binds itself automatically to every `LanguageModel`
reachable from the program (and their `.fallback` chains) when
`program.compile()` is called, and counters are summed across all.
Example (with a concrete subclass):
```python
program.compile(
metrics=[
synalinks.metrics.InputTokens(),
],
)
```
"""
_collect = staticmethod(language_models)
_tracked_suffixes = _TRACKED_SUFFIXES
@property
def language_models(self):
return list(self._models)
|